package com.yinhe.music.yhmusic.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.log.MLog;
import com.yinhe.music.yhmusic.model.MyRadioItem;
import com.yinhe.music.yhmusic.model.RadioListInfo;

import java.util.List;

/**
 * Created by hasee on 2017/8/23.
 */

public class MyRadioAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public static final int TYPE_TITLE = 0;
    public static final int TYPE_ITEM = 1;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MyRadioAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_TITLE, R.layout.expandable_item);
        addItemType(TYPE_ITEM, R.layout.dialog_collection_item);
    }

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     */


    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case 0:
                final MyRadioItem titleItem = (MyRadioItem) item;
                helper.setText(R.id.expand_title, titleItem.title + "(" + titleItem.count + ")")
                        .setGone(R.id.expand_img, false);
                break;
            case 1:
                final RadioListInfo mList = (RadioListInfo) item;
                if (mList != null){
                    MLog.debug("hxh",mList.getRadioName());
                }

                ImageView image = helper.getView(R.id.image);
                GlideHelper.setImageResource(image, mList.getImage(), R.drawable.default_cover);
                helper.setText(R.id.menu_name, mList.getRadioName())
                        .setText(R.id.song_sum, mList.getUpdateTime());
                break;
            default:
                break;
        }
    }
}
